package cn.cdqf.zuul.filter;

import com.netflix.zuul.exception.ZuulException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

@Component//要正式工作的filter需要交给spring管理
@Slf4j
public class AccessLogFilter extends AbstractPostZuulFilter {
    @Override
    public int filterOrder() {
        //最后的filter-1
        return FilterConstants.SEND_RESPONSE_FILTER_ORDER-1;
    }

    @Override
    public Object run() throws ZuulException {
        Long startTime = (Long) requestContext.get("startTime");
        log.info("当前请求:{},执行的时间为:{}",requestContext.getRequest().getRequestURI(),System.currentTimeMillis()-startTime);
        //只有最后一个filter了,没有我自己定义的filter了,不用设置true
        return null;
    }
}
